package com.world.rickcloudendpoint.api.controller;

import com.world.rickcloudendpoint.common.Result;
import com.world.rickcloudendpoint.common.exception.ClientException;
import com.world.rickcloudendpoint.common.exception.ErrorInfo;
import com.world.rickcloudendpoint.common.exception.ModuleException;
import com.world.rickcloudendpoint.models.entity.Semaphore;
import io.swagger.annotations.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @description: 音响信号接口
 * @author: jlsong
 * @date: 2022/01/21 21:47:37
 * @version: 1.0
 */
@ApiModel(value = "semaphoreApi", description = "Rest Api for semaphore operation")
public interface SemaphoreApi {

    @ApiOperation(value = "新增音响信号", notes = "新增音响信号", response = Result.class, tags = {})
    @ApiResponses(value = {
            @ApiResponse(code = 201, message = "成功获取", response = Semaphore.class),
            @ApiResponse(code = 400, message = "请求参数体异常", response = ErrorInfo.class),
            @ApiResponse(code = 401, message = "需进行身份验证", response = ErrorInfo.class),
            @ApiResponse(code = 403, message = "无权访问该接口", response = ErrorInfo.class),
            @ApiResponse(code = 404, message = "查无数据", response = Void.class),
            @ApiResponse(code = 500, message = "服务错误", response = ErrorInfo.class)})
    @PostMapping(value = "/semaphore", produces = {"application/json"})
    Result<Semaphore> addSemaphore(@ApiParam(value = "新增音箱", required = true) @Validated @RequestBody Semaphore payload) throws ClientException, ModuleException;

    @ApiOperation(value = "修改音响信号", notes = "修改音响信号", response = Result.class, tags = {})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功获取", response = Semaphore.class),
            @ApiResponse(code = 400, message = "请求参数体异常", response = ErrorInfo.class),
            @ApiResponse(code = 401, message = "需进行身份验证", response = ErrorInfo.class),
            @ApiResponse(code = 403, message = "无权访问该接口", response = ErrorInfo.class),
            @ApiResponse(code = 404, message = "查无数据", response = Void.class),
            @ApiResponse(code = 500, message = "服务错误", response = ErrorInfo.class)})
    @PutMapping(value = "/semaphore", produces = {"application/json"})
    Result<Semaphore> editSemaphore(@ApiParam(value = "修改音箱", required = true) @RequestBody Semaphore payload) throws ClientException, ModuleException;

    @ApiOperation(value = "批量删除音响信号", notes = "批量删除音响信号", response = Result.class, tags = {})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功获取", response = Long.class),
            @ApiResponse(code = 400, message = "请求参数体异常", response = ErrorInfo.class),
            @ApiResponse(code = 401, message = "需进行身份验证", response = ErrorInfo.class),
            @ApiResponse(code = 403, message = "无权访问该接口", response = ErrorInfo.class),
            @ApiResponse(code = 404, message = "查无数据", response = Void.class),
            @ApiResponse(code = 500, message = "服务错误", response = ErrorInfo.class)})
    @DeleteMapping(value = "/semaphores/{ids}", produces = {"application/json"})
    Result<Long> delSemaphores(@ApiParam(value = "ids->'id1,id2,...,idN", required = true) @PathVariable("ids") String ids) throws ClientException, ModuleException;


    @ApiOperation(value = "批量新增音响信号", notes = "批量新增音响信号", response = Result.class, tags = {})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功获取", response = Object.class),
            @ApiResponse(code = 400, message = "请求参数体异常", response = ErrorInfo.class),
            @ApiResponse(code = 401, message = "需进行身份验证", response = ErrorInfo.class),
            @ApiResponse(code = 403, message = "无权访问该接口", response = ErrorInfo.class),
            @ApiResponse(code = 404, message = "查无数据", response = Void.class),
            @ApiResponse(code = 500, message = "服务错误", response = ErrorInfo.class)})
    @PostMapping(value = "/semaphores", produces = {"application/json"})
    Result<Object> addSemaphores(@RequestBody List<Semaphore> payload) throws ClientException, ModuleException;


    @ApiOperation(value = "根据条件获取音响信号", notes = "根据条件获取音响信号", response = Result.class, tags = {})
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "成功获取", response = Object.class),
            @ApiResponse(code = 400, message = "请求参数体异常", response = ErrorInfo.class),
            @ApiResponse(code = 401, message = "需进行身份验证", response = ErrorInfo.class),
            @ApiResponse(code = 403, message = "无权访问该接口", response = ErrorInfo.class),
            @ApiResponse(code = 404, message = "查无数据", response = Void.class),
            @ApiResponse(code = 500, message = "服务错误", response = ErrorInfo.class)})
    @GetMapping(value = "/semaphores", produces = {"application/json"})
    Result<Object> listSemaphores(@ApiParam(value = "查询过滤表达式，例如:((a|b)&c)|((a&b&d)|e)") @RequestParam(value = "exp", required = false) String exp,
                                  @ApiParam("查询过滤表达式对应字典sql，例如：{'a': object, 'b': object, 'c': object, 'd': object, 'e': object}。说明：object->{'field': 'id', 'op': 'eq|ne|gt|lt|gte|lte|in|nin|like', 'value': 1}") @RequestParam(value = "dsl", required = false) String dsl,
                                  @ApiParam(value = "结果列表偏移量", defaultValue = "0") @RequestParam(value = "offset", required = false, defaultValue = "0") Long offset,
                                  @Min(-1) @ApiParam(value = "预期获取数量,最小值-1表示获取全部", defaultValue = "200") @RequestParam(value = "size", required = false, defaultValue = "200") Integer size,
                                  @NotNull @ApiParam(value = "排序字段，默认为添加时间倒序", required = true) @RequestParam(value = "sortField") String sortField,
                                  @NotNull @ApiParam(value = "排序方式:asc|desc，默认倒序desc", required = true, allowableValues = "desc,asc") @RequestParam(value = "sortBy") String sortBy) throws ClientException, ModuleException;
}
